#include <unistd.h>
#include <sys/wait.h>

int main(int argc,char** argv)
{
  int fd[2];
  pipe(fd);
  int i;
  pid_t pid;
  for(i = 0;i < 2;i++)
  {
    pid = fork();
    if(pid == 0)
    {
      break;
    }
  }
  
  if(i == 0)
  {
    close(fd[0]);
    dup2(fd[1],STDOUT_FILENO);
    execlp("ls","ls",NULL);
    close(fd[1]);
  }

  if(i == 1)
  {
    sleep(1);
    close(fd[1]);
    dup2(fd[0],STDIN_FILENO);
    execlp("wc","wc","-w",NULL);
    close(fd[0]);
  }
  if(pid == 0)
  {
    sleep(2);
    for(int j = 0;j < 2;j++)
    {
      wait(NULL);
    }
  }
  
  return 0;
}
